package org.robert.export_client.config.executor;

import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @Description  公共消息线程池
 * @Author robert
 * @Date 2022/11/17 20:16
 **/

public class ExportExecutorFactory implements ThreadFactory  {

    private static final AtomicInteger POOL_NUMBER = new AtomicInteger(1);
    private static final AtomicInteger THREAD_NUMBER = new AtomicInteger(1);

    private final String namePrefix;

    public ExportExecutorFactory(String key) {
        this.namePrefix = key + "-pool-"+ POOL_NUMBER.getAndIncrement()+"-thread-";
    }

    @Override
    public Thread newThread(Runnable r) {
        if(r == null){
            throw new NullPointerException();
        }
        return new Thread(r, namePrefix+ THREAD_NUMBER.getAndIncrement());
    }
}
